#include"Stack.h"
void STInit(ST* ps)
{
	assert(ps);
	ps->a = NULL;
	ps->top = 0;
	ps->capacity = 0;
}
void STDestory(ST* ps)
{
	assert(ps);
	free(ps->a);
	ps->a = NULL;
	ps->top = 0;
	ps->capacity = 0;
}
void STPush(ST* ps, DaTatype x)
{
	assert(ps);
	if (ps->top == ps->capacity)
	{
		int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		DaTatype* newa = (DaTatype*)realloc(ps->a, sizeof(DaTatype)*newcapacity);
		if (newa == NULL)
		{
			perror("realloc fail");
			exit(-1);
		}
		ps->a = newa;
		ps->capacity = newcapacity;
	}
	ps->a[ps->top] = x;
	ps->top++;
}
void STPop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	ps->top--;
}
DaTatype STTop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	return ps->a[ps->top - 1];
}
int STsize(ST* ps)
{
	assert(ps);
	return ps->top;
}
int  STEmpty(ST* ps)
{
	assert(ps);
	if (ps->top == 0)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}